<template>
  <div class="main">
  <el-table
    :data="tableData"
    :header-cell-style="{background:'#f2f2f2',lineHeight:'3',textAlign:'center'}"
    :cell-style="{textAlign: 'center'}"
    style="width: 100%">
    <el-table-column
      prop="date"
      label="时间"
      width=320>
    </el-table-column>
    <el-table-column
      prop="ip"
      label="IP"
      width="320">
    </el-table-column>
    <el-table-column
      prop="location"
      label="地区"
      width="320">
    </el-table-column>
    <el-table-column
      prop="browser"
      label="浏览器"
      width="320">
    </el-table-column>
  </el-table>

    <!-- 分页-->
    <div class="left">
    <span class="demonstration"></span>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes=[5,10,20,30,40,50,100]
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    </div>
  </div>
</template>

<script>
import log from '../../api/log'

export default {
  data() {
    return {
      tableData: [],
      currentPage: 1,
      pageSize: 10,
      total: 10
    }
  },
  created() {
    this.initData();
  },
  methods: {
    // 查询数据
    initData () {
      log.getList(this.currentPage, this.pageSize).then(res => {
        console.log('======'+res.data.data)
        this.tableData = res.data.data
        this.total = res.data.total
      })
    },
    //分页处理
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val
      this.initData()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val
      this.initData()
    }
  }
}
</script>

<style>
.main {
  background-color: #ffffff;
  text-align: center;
  line-height: 160px;
  padding: 30px;
  border: whitesmoke;
}
</style>
